//
//  EcgNoTouchTipView.m
//  CareRingApp
//
//  Created by Linktop on 2024/4/2.
//

#import "EcgNoTouchTipView.h"
#import "UIView+LayoutDirection.h"

@implementation EcgNoTouchTipView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.titleLabel.text = @"How to Take an ECG";//_L2(L_ECG_USE_TITL);
        [self.contentView addSubview:self.imageV];
        [self.contentView addSubview:self.txtView];
        
        [self.imageV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.imageV.superview.mas_leading).offset(5);
            make.trailing.equalTo(self.imageV.superview.mas_trailing).inset(5);
            make.top.equalTo(self.titleLabel.mas_bottom);

        }];
        
        [self.txtView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.equalTo(self.imageV);
            make.bottom.equalTo(self.txtView.superview.mas_bottom).inset(10);
            make.top.equalTo(self.imageV.mas_bottom).offset(5);
        }];
        
        
    }
    return self;
}

-(UIImageView *)imageV
{
    if (!_imageV) {
        _imageV = [UIImageView new];
        _imageV.image = [UIImage imageNamed:@"ecg_touch_bg"];
    }
    return _imageV;
}


-(UITextView *)txtView
{
    if (!_txtView) {
        _txtView = [UITextView new];
        _txtView.editable = NO;
        NSString *desc = @"Recording an ECG typically takes 30 second.\r\nReset your palms on a table or in your lap, and hold your finger on the ring.\r\nNote:\r\n1. Please keep the ring close to your phone to ensure stable Bluetooth communication.\r\n2. To take an accurate ECG, your ring needs to be snug on the finger you selected in Settings.";
        _txtView.attributedText = [[self class] resultDesc:desc Title:nil LayoutFromLeft:self.directionFromLeft ];
        _txtView.backgroundColor = UIColor.whiteColor;
        _txtView.textColor = UIColor.darkTextColor;
    }
    return _txtView;
}

+(NSMutableAttributedString *)resultDesc:(NSString *)desc Title:(NSString *)titleString LayoutFromLeft:(BOOL)lyFromLeft {


    // 链接
    NSMutableAttributedString *allString = [[NSMutableAttributedString alloc]init];

    if (titleString.length) {

        NSString *str_sub_b = titleString;
        NSMutableAttributedString *sub_b = [[NSMutableAttributedString alloc] initWithString:str_sub_b];
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.lineSpacing = 8.0;
        paragraph.paragraphSpacing = 12.0;
        paragraph.alignment = NSTextAlignmentCenter;
        [sub_b addAttribute:NSParagraphStyleAttributeName
                                         value:paragraph
                                         range:NSMakeRange(0, [str_sub_b length])];
        [sub_b addAttributes: @{NSFontAttributeName : [UIFont fontWithName:FONT_ARIAL_BOLD size:20],
                                NSForegroundColorAttributeName : [UIColor whiteColor],

        } range:NSMakeRange(0, str_sub_b.length)];

        [allString appendAttributedString:sub_b];

    }
    

    //privacy label 富文本
    UIFont *privacyFont =  [UIFont systemFontOfSize:17.0];
    NSString *str_sub_a = desc;//@"Agree to Nexchair`s ";
    NSMutableAttributedString *privacyAttString = [[NSMutableAttributedString alloc]init];
    
    if (desc.length) {
        NSAttributedString *sub_a = [[NSAttributedString alloc] initWithString:str_sub_a attributes:@{NSFontAttributeName : privacyFont,
                                                                                                      NSForegroundColorAttributeName : [UIColor darkTextColor],}
                                     ];
        [privacyAttString appendAttributedString:sub_a];




        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.alignment = lyFromLeft ? NSTextAlignmentLeft:NSTextAlignmentRight;
        paragraphStyle.lineSpacing = 5.0;
        paragraphStyle.paragraphSpacing = 8.0;
        [privacyAttString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, privacyAttString.string.length)];

        [allString appendAttributedString:privacyAttString];
    }

   

    return allString;
}



@end
